﻿// CWndAddParam.cpp: 实现文件
//

#include "pch.h"
#include "GameHacker.h"
#include "CWndAddParam.h"
#include "afxdialogex.h"
#include "CMemContext.h"
extern DATA_TYPE data_type[12];

// CWndAddParam 对话框

IMPLEMENT_DYNAMIC(CWndAddParam, CDialogEx)

CWndAddParam::CWndAddParam(CWnd* pParent /*=nullptr*/)
	: CDialogEx(IDD_ADDPARAM, pParent)
	, sType(_T(""))
	, sName(_T(""))
	, sNote(_T(""))
{

}

CWndAddParam::~CWndAddParam()
{
}

void CWndAddParam::DoDataExchange(CDataExchange* pDX)
{
	CDialogEx::DoDataExchange(pDX);
	DDX_Control(pDX, IDC_COMBO1, m_lstType);
	DDX_Text(pDX, IDC_EDIT2, sType);
	DDX_Text(pDX, IDC_EDIT1, sName);
	DDX_Text(pDX, IDC_EDIT11, sNote);
}


BEGIN_MESSAGE_MAP(CWndAddParam, CDialogEx)
	ON_BN_CLICKED(IDOK, &CWndAddParam::OnBnClickedOk)
END_MESSAGE_MAP()


// CWndAddParam 消息处理程序


BOOL CWndAddParam::OnInitDialog()
{
	CDialogEx::OnInitDialog();

	for (auto& x : data_type) {
		m_lstType.AddString(x.sName);
	}
	m_lstType.SetCurSel(nTypeId);

	return TRUE;  // return TRUE unless you set the focus to a control
				  // 异常: OCX 属性页应返回 FALSE
}

void CWndAddParam::Init(PCParamContext _params)
{
	Params = _params;
}


void CWndAddParam::OnBnClickedOk()
{
	UpdateData(TRUE);
	if (sType == L"") {
		auto sel = m_lstType.GetCurSel();
		sType = data_type[sel].sName;
	}
	while (Params) {
		if (Params->sName == sName) {
			AfxMessageBox(L"参数名重复");
			return;
		}
		Params = Params->Next;
	}
	UpdateData(FALSE);
	CDialogEx::OnOK();
}
